package com.ruoyi.worklog.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.worklog.domain.WlLeaderMember;
import com.ruoyi.worklog.domain.WlStaffProject;
import com.ruoyi.worklog.service.WlLeaderMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author cw
 * @Date 2022/7/21 - 07 - 21
 * @Description com.ruoyi.worklog.controller
 */

@RestController
@RequestMapping("/worklog/leaderAndMember")
public class leaderMemberController extends BaseController {
    @Autowired
    private WlLeaderMemberService wlLeaderMemberService;

    /**
     * 查询员工-项目关系列表
     */

    //  @PreAuthorize("@ss.hasPermi('worklog:project:Projectlist')")
    @GetMapping("/Memberids/{leaderId}")
    public TableDataInfo Memberlist(@PathVariable("leaderId") Long leaderId){
        List<Long> membersIdList = wlLeaderMemberService.selectMembers(leaderId);
        return getDataTable(membersIdList);
    }

    // @PreAuthorize("@ss.hasPermi('worklog:project:Stafflist')")
    @GetMapping("/leaderids/{memberId}")
    public TableDataInfo Leaderlist(@PathVariable("memberId") Long memberId){
        List<Long> leaderIdList =  wlLeaderMemberService.selectLeader(memberId);
        return getDataTable(leaderIdList);
    }

    /**
     * 新增员工-项目关系
     */
//    @PreAuthorize("@ss.hasPermi('worklog:project:add')")
//    @Log(title = "员工-项目关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody WlLeaderMember wlLeaderMember)
    {
        return toAjax(wlLeaderMemberService.insertLeaderMember(wlLeaderMember));
    }

//    @PreAuthorize("@ss.hasPermi('worklog:project:remove2')")
//    @Log(title = "员工-项目关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(@Validated @RequestBody WlLeaderMember wlLeaderMember)
    {
        return toAjax(wlLeaderMemberService.deleteLeaderMember(wlLeaderMember.getLeader_id(),wlLeaderMember.getMember_id()));
    }

    /**
     * 删除员工-项目关系
     */
//    @PreAuthorize("@ss.hasPermi('worklog:project:remove')")
   // @Log(title = "员工-项目关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/deletebyleader/{leaderId}")
    public AjaxResult removebyleader(@PathVariable long leaderId)
    {
        return toAjax(wlLeaderMemberService.deleteLeaderMemberByLeader(leaderId));
    }

    @DeleteMapping("/deletebymember/{memberId}")
    public AjaxResult removebymember(@PathVariable long memberId)
    {
        return toAjax(wlLeaderMemberService.deleteLeaderMemberByMember(memberId));
    }


}
